/*
 * @Author: jhy
 * @Date: 2024-07-10 17:54:26
 * @LastEditTime: 2024-07-11 14:25:35
 * @LastEditors: jhy
 * @Description: 
 * @FilePath: /next-admin/src/db.ts
 */
import mongoose from 'mongoose';

export async function connect() {
    try{
        mongoose.connect(process.env.MONGO_URI!);
        const connection = mongoose.connection;

        connection.on('connected', () => {
            console.log("MongoDB connected successfully");
        })

        connection.on('error', (err) => {
            console.log('MongoDB connection error' + err);
            process.exit();
        })
    } catch (error) {
        console.log(error);
    }
}